package com.jxt.myjxtmanager.ui.activity;

import android.text.TextUtils;
import android.widget.TextView;

import com.inqbarna.tablefixheaders.TableFixHeaders;
import com.jxt.myjxtmanager.BaseActivity;
import com.jxt.myjxtmanager.R;
import com.jxt.myjxtmanager.entity.CourseListBean;
import com.jxt.myjxtmanager.ui.inter.CourseInter;
import com.jxt.myjxtmanager.ui.presenter.CoursePresenter;
import com.jxt.myjxtmanager.ui.tableadapter.CourseNexusAdapter;
import com.jxt.myjxtmanager.utils.TimeCalculate;
import com.jxt.myjxtmanager.utils.ToastUtil;

import java.util.List;

/**
 * 课程安排
 * Created by qm on 2017/3/8 0008.
 * 暂且规定 第一节课 8:30~9:15  第二节 9:25~10:05  第三节 10:25~11:05  第四节 11:15~12:00   午休 12:00~14:00   第五节  14:00~15:40  第六节 15:50~16:35
 */
public class CourseActivity extends BaseActivity implements CourseInter {

    private TextView tv_course_time;//当前日期
    private TextView tv_course_class;//班级
    private TextView tv_course_state;//当前课程情况
    private TextView tv_course_teacher;//任课老师
    private TextView tv_course_teacher_phone;//任课教师联系方式

    private TableFixHeaders tableFixHeaders;
    private CoursePresenter presenter;
    private List<CourseListBean.CourseBean> dataList;
    private CourseNexusAdapter courseNexusAdapter;


    @Override
    public void setMyAdapter() {
        presenter.dismissDialog();
        dataList = presenter.getDataList();
        if (dataList == null || dataList.size() <= 0) return;

        presenter.setTextVelue(tv_course_state, tv_course_teacher, tv_course_teacher_phone);

        if (!TextUtils.isEmpty(dataList.get(0).getClassName())) {
            tv_course_class.setText("班级： " + dataList.get(0).getClassName());
        }
        if (courseNexusAdapter == null) {
            courseNexusAdapter = new CourseNexusAdapter(this, this, presenter);
//        baseTableAdapter.setDeviceOutLine(presenter.getDeviceOutLine());
            courseNexusAdapter.setDevicesDates(dataList);
            tableFixHeaders.setAdapter(courseNexusAdapter);
        } else {
            courseNexusAdapter.setDevicesDates(dataList);
            courseNexusAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void updateRecycler() {

    }

    @Override
    public void showToastMsg(String msg) {
        if (!TextUtils.isEmpty(msg)) {
            ToastUtil.showToast(this, msg);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_course;
    }

    private void bindView() {
        tv_course_time = (TextView) findViewById(R.id.tv_course_time);
        tv_course_class = (TextView) findViewById(R.id.tv_course_class);
        tv_course_state = (TextView) findViewById(R.id.tv_course_state);
        tv_course_teacher = (TextView) findViewById(R.id.tv_course_teacher);
        tv_course_teacher_phone = (TextView) findViewById(R.id.tv_course_teacher_phone);
        tableFixHeaders = (TableFixHeaders) findViewById(R.id.table);
    }

    @Override
    protected void initView() {
        setToolbarTitle("课程安排");
        setToolbarNavigationIcon(R.drawable.ic_left_return);
        bindView();
        tv_course_time.setText("日期： " + TimeCalculate.StringData());
        presenter = new CoursePresenter(this, this);
        presenter.RequestData();

    }

    @Override
    public void onClickLeftMenu() {
        super.onClickLeftMenu();
    }

}
